﻿#include "FITKPhyscisPropertyGeneralLaminate.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppSettings.h"
#include <QColor>

namespace Acoustics
{
    FITKPhyscisPropertyGeneralLaminate::FITKPhyscisPropertyGeneralLaminate()
    {
        this->updateDefaultColor();
    }

    FITKAcousticsAbsPhysicsProp::AcousticsPhyscisPropType FITKPhyscisPropertyGeneralLaminate::getPhysicsPropType()
    {
        return FITKAcousticsAbsPhysicsProp::AcousticsPhyscisPropType::APPGeneralLaminatePhysicalProperty;
    }


    int FITKPhyscisPropertyGeneralLaminate::getLayerCount()
    {
        //对象数量
        return this->getDataCount();
    }

    double FITKPhyscisPropertyGeneralLaminate::getTotalThickness()
    {
        //厚度
        double t = 0;
        //遍历对象
        const int n = this->getDataCount();
        for (int i =0; i<n; ++i)
        {
            FITKPhyscisPropertyGeneralLaminateIsoLayer*layer = this->getDataByIndex(i);
            if (layer == nullptr) continue;
            //每一层厚度累加
            t += layer->getThickness();
        }
        return t;
    }

    double FITKPhyscisPropertyGeneralLaminate::getShellThickness()
    {
        //获取自由阻尼层合板的总厚度
        return this->getTotalThickness();
    }

    void FITKPhyscisPropertyGeneralLaminate::updateDefaultColor()
    {
        //获取软件设置
        AppFrame::FITKAppSettings* settings = FITKAPP->getAppSettings();
        if (!settings) return;
        //获取配置
        QVariant general = settings->getVarient("GeneralPhyProp");
        //更新自由阻尼板颜色
        if (general.isNull())
        {
            general = settings->getVarient("OriGeneralPhyProp");
            if (general.isNull()) return;
        }
        QColor generalColor = general.value<QColor>();
        _color[0] = generalColor.redF();
        _color[1] = generalColor.greenF();
        _color[2] = generalColor.blueF();
    }
}
